namespace ScrumSprintMonitor.Wpf.Application
{
	#region #using Directives

	using System;
	using System.Diagnostics;

	using ContinuousLinq.Reactive;

	using Infrastructure.Configuration;

	using UI.Wpf;

	#endregion

	public class FreeBusyInfoConfiguration : ReactiveObject,
	                                         IFreeBusyInfoConfiguration
	{
		private ISprintConfiguration sprintConfiguration;

		public FreeBusyInfoConfiguration(ISprintConfiguration sprintConfiguration)
		{
			if (sprintConfiguration == null)
			{
				throw new ArgumentNullException("sprintConfiguration");
			}

			SprintConfiguration = sprintConfiguration;
		}

		protected ISprintConfiguration SprintConfiguration
		{
			[DebuggerStepThrough]
			get { return this.sprintConfiguration; }
			set
			{
				if (value == SprintConfiguration)
				{
					return;
				}

				this.sprintConfiguration = value;

				OnPropertyChanged("SprintConfiguration");
			}
		}

		#region IFreeBusyInfoConfiguration Members

		public bool ExcludeWeekends
		{
			[DebuggerStepThrough]
			get { return SprintConfiguration.ExcludeWeekends; }
		}

		public bool IsConsideredFreeTime(FreeBusyTime state)
		{
			switch (state)
			{
				case FreeBusyTime.Free:
					return true;
				case FreeBusyTime.Tentative:
					return Settings.Default.ConsiderOutlookTentativeAsFreeTime;
				case FreeBusyTime.Busy:
				case FreeBusyTime.OutOfOffice:
					return false;
				default:
					throw new ArgumentOutOfRangeException("state");
			}
		}

		#endregion
	}
}